package main

import (
	"fmt"
	"time"
)

func main() {
	// 获取当前时间
	now := time.Now()
	fmt.Printf("%v ~~~ 对应的类型为：%T\n", now, now)

	fmt.Printf("年：%v \n", now.Year())
	fmt.Printf("月：%v \n", now.Month())      //月：February
	fmt.Printf("月：%v \n", int(now.Month())) //月：2
	fmt.Printf("日：%v \n", now.Day())
	fmt.Printf("时：%v \n", now.Hour())
	fmt.Printf("分：%v \n", now.Minute())
	fmt.Printf("秒：%v \n", now.Second())
	
	// 将日期以年月日时分秒按照格式输出为字符串
	fmt.Printf("当前年月日： %d-%d-%d 时分秒：%d:%d:%d  \n", now.Year(), now.Month(), 
		now.Day(), now.Hour(), now.Minute(), now.Second())

	// Sprintf可以得到这个字符串，以便后续使用
	datestr := fmt.Sprintf("当前年月日： %d-%d-%d 时分秒：%d:%d:%d  \n", now.Year(), now.Month(), 
		now.Day(), now.Hour(), now.Minute(), now.Second())
	fmt.Println(datestr)

	// 按照指定格式
	datestr2 := now.Format("2006/01/02 15/04/05")
	fmt.Println(datestr2)

	datestr3 := now.Format("2006 15:04")
	fmt.Println(datestr3)
}
